home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / Chassis 6.0 ƒ / HelpGetProc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-22  |  5.1 KB  |  143 lines  |  [TEXT/KAHL]

  1. /************************************************************************************/
  2. /*    HelpGetProc                                                                        */
  3. /************************************************************************************/
  4. /*    How to set up this Help facility:                                                */
  5. /*                                                                                    */
  6. /*    Help 'TEXT' resources run in sequence, beginning with number 7700.  The count    */
  7. /*    is the symbol "helpCount" which is in the header file.  The first 31 characters,*/
  8. /*    followed by a carriage return, are used to build the index.  A "blank" entry    */
  9. /*    is 33 characters long:  31 blanks, a carriage return, and one more blank for    */
  10. /*    the text.  The character set is monaco 9.  With this font, the text area is 21    */
  11. /*    lines of 40 characters.  It's easiest to create the text with an editor which    */
  12. /*    will display monaco 9, then cut and paste into ResEdit.                            */
  13. /************************************************************************************/
  14.  
  15. #include "MyHeaders.h"
  16.  
  17. short HelpGetProc ()
  18. {
  19.     short            HGRetCode = 0;
  20.     div_t    r;                                        /* work area for division        */
  21.     Rect        dataBounds = {0,0, 1,1};
  22.     Point        cSize = {12,200};
  23.     short            h,v;
  24.     
  25.     if (windTbl[1].windPtr != 0)                    /* if help is already present    */
  26.         {
  27.         SelectWindow(windTbl[1].windPtr);            /* just activate the window        */
  28.         goto ENDING;
  29.         }
  30.  
  31.  
  32.     windTbl[1].windPtr =                                /* point to data area        */
  33.             (WindowPtr) &windTbl[1].windRec;
  34.     if (useColor)
  35.         windTbl[1].windPtr =                                 /* get color template*/
  36.                 GetNewCWindow (130, windTbl[1].windPtr, (WindowPtr) -1);
  37.     else
  38.         windTbl[1].windPtr =                                 /* get the template        */
  39.                 GetNewWindow (130, windTbl[1].windPtr, (WindowPtr) -1);
  40.     
  41.     windTbl[1].windRec.refCon = ProcHelp;                /* save window type            */
  42.     windTbl[1].windPathRefNum = 0;                        /* clear path ref number    */
  43.     windTbl[1].windTEChanged = FALSE;                    /* no data changed yet        */
  44.  
  45.     v = screenBits.bounds.bottom - 5                    /* compute location            */
  46.         -(windTbl[1].windRec.port.portRect.bottom        /* centered at the bottom    */
  47.             - windTbl[1].windRec.port.portRect.top);
  48.     h = (screenBits.bounds.right
  49.         -(windTbl[1].windRec.port.portRect.right
  50.             - windTbl[1].windRec.port.portRect.left)) * 0.5;
  51.     MoveWindow (windTbl[1].windPtr, h, v, TRUE);    /* position window on desktop    */
  52.  
  53.     SetPort (&windTbl[1].windRec.port);                    /* set this as the grafPort    */
  54.     TextFont(monaco);                                    /* choose the font...        */
  55.     TextFace(NIL);                                        /* ... style, and..            */
  56.     TextSize(9);                                        /* ... size                    */
  57.  
  58.     workRect = windTbl[1].windRec.port.portRect;
  59.     viewRect = workRect;
  60.     viewRect.right -= 18;
  61.     viewRect.left = viewRect.right - 255;
  62.     viewRect.top = viewRect.bottom - 233;
  63.     viewRect.bottom -= 2;
  64.     destRect = viewRect;
  65.     destRect.right -= 6;
  66.     destRect.left += 6;
  67.     windTbl[1].windTEH[0] =
  68.             TENew (&destRect, &viewRect);                /* create TE Record            */
  69.     SetClikLoop ((ProcPtr) myClikLoop,                    /* install click loop        */
  70.             windTbl[1].windTEH[0]);
  71.     TEAutoView (TRUE, windTbl[1].windTEH[0]);            /* enable AutoScroll        */
  72.     TESetSelect (0,0, windTbl[1].windTEH[0]);            /* caret to top                */
  73.     
  74.     windTbl[1].windTEHCount = 1;                        /* one TE field is defined    */
  75.     windTbl[1].windTEHSub = 0;                            /* go to first TE area        */
  76.  
  77.  
  78.  
  79.     workRect = (**windTbl[1].windTEH[0]).viewRect;
  80.     windTbl[1].windCntlH[0] =                             /* get the control        */
  81.             GetNewControl (128, windTbl[1].windPtr);
  82.     SetCtlAction (windTbl[1].windCntlH[0],                /* install own action    */
  83.             (ProcPtr) myActionProc);
  84.     SizeControl (windTbl[1].windCntlH[0], 16,            /* size to fit window    */
  85.             workRect.bottom - workRect.top + 2);
  86.     MoveControl (windTbl[1].windCntlH[0],                /* move onto window        */
  87.             workRect.right, workRect.top - 1);
  88.     ShowControl (windTbl[1].windCntlH[0]);                /* make it visible        */
  89.     
  90.     windTbl[1].windCntlHCount = 1;                        /* one Control is defined    */
  91.     windTbl[1].windCntlHSub = 0;                        /* go to first Control        */
  92.     
  93.     workRect = windTbl[1].windRec.port.portRect;
  94.     workRect.left += 4;
  95.     workRect.right = workRect.left + 200;
  96.     workRect.bottom -=2;
  97.     workRect.top = workRect.bottom - 204;
  98.  
  99.     helpList = LNew(&workRect, &dataBounds, cSize,            /* create the list        */
  100.             NIL, windTbl[1].windPtr, TRUE, FALSE, FALSE, TRUE);
  101.     (**helpList).selFlags = lOnlyOne + lNoNilHilite;    /* set flags for cursor        */
  102.  
  103.     ShowWindow (windTbl[1].windPtr);
  104.  
  105.     helpCell.h = 0;
  106.     helpCell.v = 0;
  107.     j=0;
  108.     LAddRow (helpCount-1, 1, helpList);
  109.     helpHandle = (Handle) -1;                    /* assign non-null for loop            */
  110.     for (j=0; j<helpCount; j++)
  111.         {
  112.         helpHandle = GetResource ('TEXT', 7700+j);
  113.         HLock (helpHandle);
  114.         if (helpHandle)
  115.             {
  116.             if ( (SizeResource(helpHandle)) > 32)
  117.                 LSetCell (*helpHandle, 31, helpCell, helpList);
  118.             else
  119.                 LClrCell (helpCell, helpList);
  120.             helpCell.v++;
  121.             }
  122.         HUnlock (helpHandle);
  123.         ReleaseResource (helpHandle);
  124.         }
  125.  
  126.     helpHandle = GetResource('TEXT', 7700);        /* get "How to Use Help" TEXT        */
  127.     HLock (helpHandle);
  128.     helpLong = SizeResource(helpHandle);        /* get TEXT size                    */
  129.     TESetText (*helpHandle+32, helpLong-32, windTbl[1].windTEH[0]);
  130.     TECalText (windTbl[1].windTEH[0]);
  131.     helpCell.v = 0;
  132.     helpPrev = 0;
  133.     LSetSelect (TRUE, helpCell, helpList);
  134.     HUnlock (helpHandle);
  135.     ReleaseResource (helpHandle);
  136.  
  137.     InvalRect (&windTbl[1].windRec.port.portRect);        /* request redraw        */
  138.  
  139.  
  140. ENDING:        
  141.     return HGRetCode;
  142. }
  143.